package cappuccino.couldbook.ui.Adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.List;

import cappuccino.couldbook.App;
import cappuccino.couldbook.R;
import cappuccino.couldbook.data.Group;

/**
 * Created by Administrator on 2016/9/10.
 */
public class GroupAdapter extends BaseAdapter {

    List<Group> groups;
    public GroupAdapter(List<Group> groups){
        this.groups = groups;
    }

    @Override
    public int getCount() {
        return groups.size();
    }

    @Override
    public Object getItem(int position) {
        return groups.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;

        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(App.getInstance().getApplicationContext()).inflate(R.layout.item_group,null);
            holder.text = (TextView) convertView.findViewById(R.id.tv_item_group);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.text.setText(groups.get(position).name);
        return convertView;
    }

    class ViewHolder {
        TextView text;

    }
}
